/*
 *  RESTful DDS is a prototyping effort to demonstrate how DDS could be combined
 *  with HTTP clients, extending the realm of pub/sub distribution to true wide
 *  area networking.
 *
 *  Copyright (C) 2009 PrismTech Ltd.
 *  reinier.torenbeek@gmail.com
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License Version 3 dated 29 June 2007, as published by the
 *  Free Software Foundation.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with restful-dds; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */

package org.opensplice.restful.service;

import org.restlet.Context;
import org.restlet.data.MediaType;
import org.restlet.data.Request;
import org.restlet.data.Response;
import org.restlet.resource.Representation;
import org.restlet.resource.Resource;
import org.restlet.resource.ResourceException;
import org.restlet.resource.StringRepresentation;
import org.restlet.resource.Variant;

public class TestResource extends Resource {
    public TestResource(Context context, Request request, Response response) {
        super(context, request, response);
        String sleepTimeString = (String)request.getAttributes().get("sleepTime");
        long sleepTime;

        try {
           sleepTime = Long.parseLong(sleepTimeString.trim());
        } catch (NumberFormatException nfe) {
           System.out.println("Error determining sleeptime: " + nfe.getMessage());
           sleepTime = 1;
           System.out.println("Using default value " + sleepTime);
        }

        // Allow modifications of this resource via POST requests.
        setModifiable(true);

        // Declare the kind of representations supported by this resource.
        getVariants().add(new Variant(MediaType.TEXT_PLAIN));

        DDSTester.test(sleepTime); 
    }

    @Override
    public Representation represent(Variant variant) throws ResourceException {
        Representation representation = new StringRepresentation(
                "This is a test page", MediaType.TEXT_PLAIN);
        return representation;
    }
}
